/*	$Id: sock.h 1073 2010-04-26 05:31:06Z phrakt $ */
/*
 * Copyright (c) 2003 Jean-Francois Brousseau <phrakt@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


#ifndef _HTTP_SOCK_H_
#define _HTTP_SOCK_H_

#include <sys/types.h>
#include <sys/socket.h>

#define HTTP_SOCK_INITBUFSIZE		4096


#define HTTP_SOCK_KEEPALIVE		0x0001


enum http_sock_type {
	HTTP_SOCK_LISTEN,		/* listening socket */
	HTTP_SOCK_CONN,			/* connection socket */
};


enum http_sock_state {
	HTTP_SOCK_INITIALIZED,
	HTTP_SOCK_CONNECTED,
	HTTP_SOCK_LISTENING,
	HTTP_SOCK_CLOSING,
	HTTP_SOCK_CLOSED,
};


http_sock_t*         http_sock_bind       (struct sockaddr *, socklen_t);
http_sock_t*         http_sock_connect    (http_sockaddr_t *);
http_sock_t*         http_sock_accept     (http_sock_t *, const struct timeval *);
http_sock_t*         http_sock_getref     (http_sock_t *);
int                  http_sock_close      (http_sock_t *);
int                  http_sock_getfd      (http_sock_t *);
int                  http_sock_getladdr   (http_sock_t *, http_sockaddr_t *);
int                  http_sock_getraddr   (http_sock_t *, http_sockaddr_t *);
int                  http_sock_getlport   (http_sock_t *);
int                  http_sock_getrport   (http_sock_t *);
http_session_t*      http_sock_getsession (http_sock_t *);
enum http_sock_state http_sock_getstate   (http_sock_t *);
enum http_sock_type  http_sock_gettype    (http_sock_t *);
int                  http_sock_getflag    (http_sock_t *, int);
int                  http_sock_setflag    (http_sock_t *, int);

ssize_t              http_sock_recv       (http_sock_t *, void *, size_t);
ssize_t              http_sock_recvmsg    (http_sock_t *, http_msg_t *, int);
ssize_t              http_sock_send       (http_sock_t *, const void *, size_t);
ssize_t              http_sock_sendmsg    (http_sock_t *, http_msg_t *, int);
int                  http_sock_sendfile   (http_sock_t *, int, off_t,
					    size_t *, int);


#endif /* _HTTP_SOCK_H_ */
